$(function () {
	$("#jqGrid").jqGrid({
		url: '../tpurviewcustinfo/list',
		datatype: "json",
		colModel: [			
		{ label: '编码', name: 'number', index: 'number', width: 80 }, 			
		{ label: '公司名称', name: 'cropname', index: 'cropname', width: 80 }, 			
		{ label: '纳税人识别号', name: 'taxregnum', index: 'taxregnum', width: 80 }, 	
		{ label: '系统注册日期', name: 'sysdate', index: 'sysdate', width: 80 }, 			
		{ label: '法人代表', name: 'croplegal', index: 'croplegal', width: 80 }, 			
		{ label: '管理员账号', name: 'username', index: 'username', width: 80 }, 			
		{ label: 'IP地址', name: 'ip', index: 'ip', width: 80 }, 			
		{ label: '服务器端口', name: 'serverport', index: 'serverport', width: 80 }, 			
		{ label: '创建人', name: 'creatname', index: 'creatname', width: 80 }, 			
		{ label: '创建时间', name: 'creatdate', index: 'creatdate', width: 80 }, 			
		],
		viewrecords: true,
		height: 385,
		rowNum: 10,
		rowList : [10,30,50],
		rownumbers: true, 
		rownumWidth: 25, 
		autowidth:true,
		multiselect: true,
		pager: "#jqGridPager",
		jsonReader : {
			root: "page.list",
			page: "page.currPage",
			total: "page.totalPage",
			records: "page.totalCount"
		},
		prmNames : {
			page:"page", 
			rows:"limit", 
			order: "order"
		},
		gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
      });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		tPurviewCustinfo: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.tPurviewCustinfo = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
			vm.title = "修改";

			vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var legalObj = {
				number: true,
				cropname: true,
				taxregnum: true,
				sysdate: true
			};
			// 非空校验
			if(!oneRowIsLegal(vm.tPurviewCustinfo,legalObj)){
				alert('请先输入必填项');
				return;
			}
			var url = vm.tPurviewCustinfo.id == null ? "../tpurviewcustinfo/save" : "../tpurviewcustinfo/update";
			$.ajax({
				type: "POST",
				url: url,
				contentType: "application/json",
				data: JSON.stringify(vm.tPurviewCustinfo),
				success: function(r){
					if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
					url: "../tpurviewcustinfo/delete",
					contentType: "application/json",
					data: JSON.stringify(ids),
					success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../tpurviewcustinfo/info/"+id, function(r){
				// 处理时间
				r.tPurviewCustinfo.sysdate = dateInputFormatter(r.tPurviewCustinfo.sysdate);
				vm.tPurviewCustinfo = r.tPurviewCustinfo;
			});
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
				page:page
			}).trigger("reloadGrid");
		}
	}
});